#include <iostream>
using namespace std;
#include <map>
#include <string>
#include <vector>
int main()
{

#if 0
    // 自动类型推导
    int x = 6;
    auto b = 3.14;
    cout << "x=" << x << endl;
    cout << "b=" << b << endl;

    map<int,string>mymap;
    mymap[43639]="张三";
    mymap[23456]="李四";

    for(std::map<int,string>::iterator iter= mymap.begin();iter!= mymap.end();iter++)
    {
        cout << "key=" << iter->first << " ,value=" << iter->second << endl;
    }

    for(auto iter= mymap.begin();iter!= mymap.end();iter++)
    {
        cout << "key=" << iter->first << " ,value=" << iter->second << endl;
    }
#endif

#if 0

vector<int>myvec={11,22,3,44,55};

for (int i = 0; i < myvec.size(); i++)
{
    cout<< myvec[i] <<"\t";
}
cout << endl;

for(auto iter=myvec.begin();iter!=myvec.end();iter++)
{
    cout << *iter<<"\t";
}
cout << endl;

for(auto& ele :myvec)
{
    cout << ele << "\t";
}
cout << endl;

#endif

#if 1 // 捕获列表
    int a = 5, b = 10, c = 100;
    // 按值捕获
    // 值传递不能修改参数的值
    auto test = [a, b]()
    {
        return a + b;
    };
    int ret = test();
    cout << "ret=" << ret << endl;

    // 按引用捕获
    // 引用传递可以修改参数的值
    auto test2 = [&a, &c]()
    { return a + c; };
    cout << test2() << endl;

    // 混合捕获---按值捕获和按引用捕获混合捕获
    auto test3 = [&c, b]()
    { return c + b; };
    cout << test3() << endl;

    // "="捕获所有
    auto test4 = [=]()
    { return a + b + c; };
    cout << test4() << endl;

    /*参数列表 */
    auto test5 = [](int x, int y)
    { return x + y; };
    cout << test5(1, 2) << endl;

    // 显示指定返回类型
    auto test6 = [=](int x, int y) -> int
    { return x + y - c; };
    cout << test6(1, 2) << endl;

    // mutable 修改函数参数

    int g = 666;
    auto test7 = [g]() mutable
    {g=777;return g + 100; };
    cout << test7() << endl;

#endif
}